/**
 * Created by ztt on 2017/11/17.
 */
import express from "express";
import { createUserApi } from "./user/user.js";

import path from "path";
import { fileURLToPath } from "url";
const __filenameNew = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filenameNew);

const app = express();
app.get("/", function (req, res, next) {
  res.sendFile(__dirname + "/index.html");
});
/**
 * todo:跨域处理
 */
app.all("*", function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("X-Powered-By", " 3.2.1");
  res.header("Content-Type", "application/json;charset=utf-8");
  next();
});

createUserApi(app);

let server = app.listen(3000, function () {
  let host = server.address().address;
  let port = server.address().port;
  console.log("host:", host);
  console.log("应用实例，访问地址为 http://%s:%s", "localhost", port);
});
